home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*------------------------------------------------------------------------------
- * OORT - dashboard.c - Routines for drawing dashboard.
- *
- * $Id: dashboard.c,v 1.2 1994/01/28 00:17:21 mtj Exp $
- *
- * Chris Fouts - May, 1993.
- *
- *----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
- #include <unistd.h>
- #include <math.h>
- #include <sys/param.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <bstring.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <arpa/inet.h>
- #include <gl/device.h>
-
- #include <pf.h>
-
- #include "oort.h"
- #include "text.h"
- #include "radar.h"
- #include "gameio.h"
- #include "dashboard.h"
-
- /* BEGIN PROTOTYPES -S dashboard.c */
- static void drawFrames( void ) ;
- static void drawOneFrame( pfVec3 tl, pfVec3 tr, pfVec3 bl, pfVec3 br,
- long topColor, long leftColor, long rightColor,
- long bottomColor ) ;
- static void formatMessage( void ) ;
- static void initTextScreen( void ) ;
- static void interpVec3( pfVec3 a, float v, pfVec3 b, pfVec3 c ) ;
- static void locateGauges( void ) ;
- static void repaintDashboard( void ) ;
- static void showHeading( void ) ;
- static void showPlayers( void ) ;
- static void showScores( void ) ;
- static void showText( void ) ;
- /* END PROTOTYPES -S dashboard.c */
-
-
- #define MAX_MSG_LINES 3
-
- int needToRepaint = 1 ;
- int sendingMessage = 0 ;
- static int textScreenLine = 0 ;
- static int repaintTextScreen = 2 ;
- static int repaintScores = 2 ;
- static int repaintPlayers = 2 ;
- static char textLines[MAX_TEXT_LINES][MAX_MSG_SIZE] ;
- static char msgLines[MAX_MSG_LINES][MAX_MSG_SIZE] ;
- static char message[MAX_MSG_SIZE] ;
- static int nMsgLines ;
- static int nMsgChars ;
- static int reformatMessage = 0 ;
- static char mailMode ;
-
- BarGraph speedometerBG ;
- BarGraph shieldsBG ;
- BarGraph powerBG ;
- BarGraph laserBG ;
- BarGraph cloakBG ;
-
- extern int nTextLines ;
- extern int numberPlayers ;
- extern float speed ;
- extern float power ;
- extern float shields ;
- extern float laser ;
- extern float cloak ;
- extern float topSpeed ;
- extern ViewPort radarVP ;
- extern pfLight *Sun ;
- extern GeoFont *helvFont ;
-
- static ViewPort dashboardVP ;
- static float dashboardAR ;
- static int dashboardFOV ;
- static float dashboardAngle ;
- static float dashboardNear = 0.1f ;
- static float dashboardFar = 5.0f ;
- static GeoFont *cf ;
- static GeoFont *hf ;
- static GeoFont *sf ;
- static float textScreenH ;
- static float textScreenW ;
- static float textScreenFontSize ;
- static float textScreenRotX ;
- static float textScreenRotY ;
- static pfVec3 textScreenBL ;
- static pfVec3 textScreenBR ;
- static pfVec3 textScreenTL ;
- static pfVec3 textScreenTR ;
- static int kills ;
- static int lives ;
-
-
- static char *compassLabel = "COMPASS" ;
- static char *radarLabel = "RADAR" ;
- static char *textScreenLabel = "INFO" ;
- static char *livesLabel = "LIVES" ;
- static char *killsLabel = "KILLS" ;
- static char *playersLabel = "PLAYERS" ;
- static struct {
- float x ;
- float y ;
- char *text ;
- } gaugeLabel[5] ;
-
- static char *gaugeText[] = {
- "SPEED",
- "SHIELD",
- "POWER",
- "LASER",
- "ECM",
- } ;
-
-
- static float backPanel[][3] = {
- { -9.00f, -0.5f, -1.5f },
- { -9.00f, -1.0f, -1.2f },
- { -1.13f, -0.5f, -1.5f },
- { -1.00f, -1.0f, -1.2f },
- { -0.42f, -0.5f, -2.0f },
- { -0.29f, -1.0f, -1.7f },
- { 0.42f, -0.5f, -2.0f },
- { 0.29f, -1.0f, -1.7f },
- { 1.12f, -0.5f, -1.5f },
- { 1.00f, -1.0f, -1.2f },
- { 9.00f, -0.5f, -1.5f },
- { 9.00f, -1.0f, -1.2f },
- } ;
-
- static float compassFrame[][3] = {
- { 0.20f, -1.0f, -1.65f },
- { -0.20f, -1.0f, -1.65f },
- { 0.20f, -1.0f, -1.25f },
- { -0.20f, -1.0f, -1.25f },
- } ;
-
- static float killsFrame[][3] = {
- { -0.30f, -1.0f, -1.35f },
- { -0.50f, -1.0f, -1.35f },
- { -0.30f, -1.0f, -1.25f },
- { -0.50f, -1.0f, -1.25f },
- } ;
-
- static float livesFrame[][3] = {
- { 0.50f, -1.0f, -1.35f },
- { 0.30f, -1.0f, -1.35f },
- { 0.50f, -1.0f, -1.25f },
- { 0.30f, -1.0f, -1.25f },
- } ;
-
- static float playersFrame[][3] = {
- { 0.10f, -1.0f, -1.15f },
- { -0.10f, -1.0f, -1.15f },
- { 0.10f, -1.0f, -1.05f },
- { -0.10f, -1.0f, -1.05f },
- } ;
-
- static float compassArrow[4][3] = {
- { 0.04f, 0.0f, 0.04f },
- { 0.00f, 0.0f, -0.14f },
- { 0.00f, 0.0f, 0.00f },
- { -0.04f, 0.0f, 0.04f },
- } ;
-
- static float radarCorner[][3] = {
- { -0.25f, -0.95f, -1.73f },
- { 0.25f, -0.55f, -1.97f },
- } ;
-
- /*------------------------------------------------------------------------------
- * Repaint the dashboard background.
- *----------------------------------------------------------------------------*/
- static void
- repaintDashboard(
- void
- )
- {
- int i ;
- float c ;
- float s ;
- pfVec2 p ;
- pfVec3 v0 ;
- pfVec3 v1 ;
-
- cpack( 0x00b0b0b0 ) ;
- clear() ;
-
- /*
- * Draw compass background.
- */
- cpack( 0x0 ) ;
- bgntmesh() ;
- v3f( compassFrame[0] ) ;
- v3f( compassFrame[1] ) ;
- v3f( compassFrame[2] ) ;
- v3f( compassFrame[3] ) ;
- endtmesh() ;
-
- pfPushMatrix() ;
- translate( 0.0f, -1.0f, -1.45f ) ;
- rot( -90.0f, 'x' ) ;
- positionText( -0.5f * getStrWidth( hf, compassLabel ),
- -0.22f - getFontSize( hf ) ) ;
- drawString( hf, compassLabel ) ;
- cpack( 0x00ffffff ) ;
- bgnline() ;
- for( i = 0 ; i <= 36 ; i++ )
- {
- pfSinCos( i * 10.0f, &s, &c ) ;
- PFSET_VEC2( p, 0.18f * s, 0.18f * c ) ;
- v2f( p ) ;
- }
- endline() ;
- PFSET_VEC3( v0, 0.15f, 0.0f, 0.0f ) ;
- PFSET_VEC3( v1, 0.18f, 0.0f, 0.0f ) ;
- for( i = 0 ; i < 8 ; i++ )
- {
- bgnline() ;
- v3f( v0 ) ;
- v3f( v1 ) ;
- endline() ;
- rot( 45.0f, 'z' ) ;
- }
- pfPopMatrix() ;
-
- /*
- * Draw left panel.
- */
- cpack( 0x00808080 ) ;
- bgntmesh() ;
- v3f( backPanel[0] ) ;
- v3f( backPanel[1] ) ;
- v3f( backPanel[2] ) ;
- v3f( backPanel[3] ) ;
- cpack( 0x00606060 ) ;
- v3f( backPanel[4] ) ;
- v3f( backPanel[5] ) ;
- cpack( 0x00808080 ) ;
- v3f( backPanel[6] ) ;
- v3f( backPanel[7] ) ;
- cpack( 0x00606060 ) ;
- v3f( backPanel[8] ) ;
- v3f( backPanel[9] ) ;
- cpack( 0x00808080 ) ;
- v3f( backPanel[10] ) ;
- v3f( backPanel[11] ) ;
- endtmesh() ;
-
- /*
- * Label radar.
- */
- pfPushMatrix() ;
- cpack( 0x0 ) ;
- translate( 0.0f, radarCorner[0][1], radarCorner[0][2] ) ;
- PFSUB_VEC3( v0, radarCorner[0], radarCorner[1] ) ;
- rot( pfArcTan2( -v0[2], -v0[1] ), 'x' ) ;
- positionText( -0.5f * getStrWidth( hf, radarLabel ),
- -0.02f - getFontSize( hf ) ) ;
- drawString( hf, radarLabel ) ;
- pfPopMatrix() ;
-
- /*
- * Label gauges.
- */
- pfPushMatrix() ;
- translate( backPanel[7][0], backPanel[7][1], backPanel[7][2] ) ;
- rot( -textScreenRotY, 'y' ) ;
- rot( textScreenRotX, 'x' ) ;
- cpack( 0x0 ) ;
- for( i = 0 ; i < 5 ; i++ )
- {
- positionText( gaugeLabel[i].x, gaugeLabel[i].y ) ;
- drawString( hf, gaugeLabel[i].text ) ;
- }
- pfPopMatrix() ;
-
- /*
- * Label text screen.
- */
- pfPushMatrix() ;
- translate( textScreenBL[0], textScreenBL[1], textScreenBL[2] ) ;
- rot( textScreenRotY, 'y' ) ;
- rot( textScreenRotX, 'x' ) ;
- cpack( 0x0 ) ;
- positionText( 0.5f*( textScreenW - getStrWidth( hf, textScreenLabel ) ),
- -0.02f - getFontSize( hf ) ) ;
- drawString( hf, textScreenLabel ) ;
- pfPopMatrix() ;
-
- /*
- * Label kill counter.
- */
- pfPushMatrix() ;
- translate( -0.4f, -1.0f, -1.25f ) ;
- rot( -90.0f, 'x' ) ;
- positionText( -0.5f * getStrWidth( hf, killsLabel ),
- -0.02f - getFontSize( hf ) ) ;
- drawString( hf, killsLabel ) ;
- pfPopMatrix() ;
-
- /*
- * Label lives counter.
- */
- pfPushMatrix() ;
- translate( 0.4f, -1.0f, -1.25f ) ;
- rot( -90.0f, 'x' ) ;
- positionText( -0.5f * getStrWidth( hf, livesLabel ),
- -0.02f - getFontSize( hf ) ) ;
- drawString( hf, livesLabel ) ;
- pfPopMatrix() ;
-
- /*
- * Label player counter.
- */
- pfPushMatrix() ;
- translate( 0.0f, -1.0f, -1.05f ) ;
- rot( -90.0f, 'x' ) ;
- positionText( -0.5f * getStrWidth( hf, playersLabel ),
- -0.02f - getFontSize( hf ) ) ;
- drawString( hf, playersLabel ) ;
- pfPopMatrix() ;
-
- drawFrames() ;
-
- repaintTextScreen = 2 ;
- repaintScores = 2 ;
- repaintPlayers = 2 ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the position of the dashboard and radar.
- *----------------------------------------------------------------------------*/
- void
- setDashboardPosition(
- int left,
- int right,
- int bottom,
- int top
- )
- {
- float fovx ;
- float cotangent ;
- float c ;
- float s ;
- float cx ;
- float cy ;
- float sx ;
- float sy ;
- pfVec4 pt ;
- pfMatrix m ;
-
- /*
- * Determine location of dashboard.
- */
- dashboardVP.left = left ;
- dashboardVP.right = right ;
- dashboardVP.bottom = bottom ;
- dashboardVP.top = top ;
-
- /*
- * Determine aspect ratio and field of view for dashboard.
- */
- dashboardAR = (float)( dashboardVP.right - dashboardVP.left ) /
- (float)( dashboardVP.top - dashboardVP.bottom ) ;
- dashboardFOV = 320 ;
- fovx = 2.0f * pfArcTan2( dashboardAR * pfTan( .05f * dashboardFOV ),
- 1.0f ) ;
- if( fovx < 70.0f )
- {
- dashboardFOV = (int)( 20.0f *
- pfArcTan2( pfTan( 70.f / 2.f ) / dashboardAR, 1.0f ) );
- }
- dashboardAngle = (float)dashboardFOV / 20.0f + pfArcTan2( 0.5f, 2.0f ) ;
-
- /*
- * Build "projection" matrix for determining location of radar viewport.
- */
- pfSinCos( (float)dashboardFOV / 20.0f, &s, &c ) ;
- cotangent = c / s ;
- pfSinCos( dashboardAngle, &s, &c ) ;
-
- m[0][0] = cotangent / dashboardAR ;
- m[0][1] = 0.0f ;
- m[0][2] = 0.0f ;
- m[0][3] = 0.0f ;
-
- m[1][0] = 0.0f ;
- m[1][1] = cotangent * c ;
- m[1][2] = -s * ( dashboardFar + dashboardNear ) /
- ( dashboardFar - dashboardNear ) ;
- m[1][3] = -s ;
-
- m[2][0] = 0.0f ;
- m[2][1] = -cotangent * s ;
- m[2][2] = -c * ( dashboardFar + dashboardNear ) /
- ( dashboardFar - dashboardNear ) ;
- m[2][3] = -c ;
-
- m[3][0] = 0.0f ;
- m[3][1] = 0.0f ;
- m[3][2] = -2.0f * ( dashboardFar * dashboardNear ) /
- ( dashboardFar - dashboardNear ) ;
- m[3][3] = 0.0f ;
-
- /*
- * Transform opposite corners of where radar is s'posed to be.
- */
- sx = 0.5 * ( dashboardVP.right - dashboardVP.left + 1.0 ) ;
- sy = 0.5 * ( dashboardVP.top - dashboardVP.bottom + 1.0 ) ;
- cx = 0.5 * ( dashboardVP.right + dashboardVP.left ) ;
- cy = 0.5 * ( dashboardVP.top + dashboardVP.bottom ) ;
-
- pt[0] = radarCorner[0][0] ;
- pt[1] = radarCorner[0][1] ;
- pt[2] = radarCorner[0][2] ;
- pt[3] = 1.0f ;
- pfXformVec4( pt, pt, m ) ;
-
- pt[0] /= pt[3] ;
- pt[1] /= pt[3] ;
-
- radarVP.left = (int)( pt[0] * sx + cx + 0.5 ) ;
- radarVP.bottom = (int)( pt[1] * sy + cy + 0.5 ) ;
-
- pt[0] = radarCorner[1][0] ;
- pt[1] = radarCorner[1][1] ;
- pt[2] = radarCorner[1][2] ;
- pt[3] = 1.0f ;
- pfXformVec4( pt, pt, m ) ;
-
- pt[0] /= pt[3] ;
- pt[1] /= pt[3] ;
-
- radarVP.right = (int)( pt[0] * sx + cx + 0.5 ) ;
- radarVP.top = (int)( pt[1] * sy + cy + 0.5 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show bar graph.
- *----------------------------------------------------------------------------*/
- void
- showBarGraph(
- BarGraph *bar
- )
- {
- bgntmesh() ;
- cpack( bar->fg ) ;
- v3f( bar->v0 ) ;
- v3f( bar->v1 ) ;
- v3f( bar->v2 ) ;
- v3f( bar->v3 ) ;
- cpack( bar->bg ) ;
- v3f( bar->v4 ) ;
- v3f( bar->v5 ) ;
- endtmesh() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the values of a bar graph.
- *----------------------------------------------------------------------------*/
- void
- setBarGraph(
- BarGraph *bar,
- float value
- )
- {
- float vm1 = 1.0f - value ;
-
- PFCOMBINE_VEC3( bar->v2, vm1, bar->v0, value, bar->v4 ) ;
- PFCOMBINE_VEC3( bar->v3, vm1, bar->v1, value, bar->v5 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize the locations of the guages.
- *----------------------------------------------------------------------------*/
- static void
- locateGauges(
- void
- )
- {
- int gl = 0 ;
- float x ;
- float y ;
- float l ;
- float width = 0.10f ;
- float gap = 0.05f ;
- float fontSize ;
- pfVec3 v ;
- pfVec3 topBack ;
- pfVec3 topFront ;
- pfVec3 botBack ;
- pfVec3 botFront ;
- pfVec3 bottom ;
- pfVec3 side ;
-
- /*
- * Set up for locating gauges along right side.
- */
- PFSUB_VEC3( bottom, backPanel[9], backPanel[7] ) ;
- PFSUB_VEC3( side, backPanel[6], backPanel[7] ) ;
- PFCOPY_VEC3( v, side ) ;
- pfNormalizeVec3( v ) ;
- l = -PFDOT_VEC3( v, bottom ) ;
- OFFSET_VEC3( side, l, bottom ) ;
-
- ADDSCALE_VEC3( botBack, backPanel[7], 0.15f, side ) ;
- ADDSCALE_VEC3( topBack, backPanel[7], 0.90f, side ) ;
-
- ADDSCALE_VEC3( botFront, backPanel[9], 0.15f, side ) ;
- ADDSCALE_VEC3( topFront, backPanel[9], 0.90f, side ) ;
-
- fontSize = 0.065f * PFLENGTH_VEC3( side ) ;
- setFontSize( hf, fontSize ) ;
- y = 0.5f * fontSize ;
-
- l = pfDistancePt3( botFront, botBack ) ;
-
- width = l / 6.0f ;
- gap = width / 5.0f ;
-
- x = gap ;
- /*
- * Locate speedometer.
- */
- gaugeLabel[gl].x = x * l +
- 0.5f * ( l * width - getStrWidth( hf, gaugeText[gl] ) ) ;
- gaugeLabel[gl].y = y ;
- gaugeLabel[gl].text = gaugeText[gl] ;
- gl++ ;
- interpVec3( speedometerBG.v0, x, botBack, botFront ) ;
- interpVec3( speedometerBG.v4, x, topBack, topFront ) ;
- x += width ;
- interpVec3( speedometerBG.v1, x, botBack, botFront ) ;
- interpVec3( speedometerBG.v5, x, topBack, topFront ) ;
- speedometerBG.fg = 0x000000ff ;
- speedometerBG.bg = 0x00000000 ;
- setBarGraph( &speedometerBG, 0.4f ) ;
- x += gap ;
-
- /*
- * Locate shields guage.
- */
- gaugeLabel[gl].x = x * l +
- 0.5f * ( l * width - getStrWidth( hf, gaugeText[gl] ) ) ;
- gaugeLabel[gl].y = y ;
- gaugeLabel[gl].text = gaugeText[gl] ;
- gl++ ;
- interpVec3( shieldsBG.v0, x, botBack, botFront ) ;
- interpVec3( shieldsBG.v4, x, topBack, topFront ) ;
- x += width ;
- interpVec3( shieldsBG.v1, x, botBack, botFront ) ;
- interpVec3( shieldsBG.v5, x, topBack, topFront ) ;
- shieldsBG.fg = 0x000000ff ;
- shieldsBG.bg = 0x00000000 ;
- setBarGraph( &shieldsBG, 0.8f ) ;
- x += gap ;
-
- /*
- * Locate power guage.
- */
- gaugeLabel[gl].x = x * l +
- 0.5f * ( l * width - getStrWidth( hf, gaugeText[gl] ) ) ;
- gaugeLabel[gl].y = y ;
- gaugeLabel[gl].text = gaugeText[gl] ;
- gl++ ;
- interpVec3( powerBG.v0, x, botBack, botFront ) ;
- interpVec3( powerBG.v4, x, topBack, topFront ) ;
- x += width ;
- interpVec3( powerBG.v1, x, botBack, botFront ) ;
- interpVec3( powerBG.v5, x, topBack, topFront ) ;
- powerBG.fg = 0x000000ff ;
- powerBG.bg = 0x00000000 ;
- setBarGraph( &powerBG, 0.8f ) ;
- x += gap ;
-
- /*
- * Locate laser guage.
- */
- gaugeLabel[gl].x = x * l +
- 0.5f * ( l * width - getStrWidth( hf, gaugeText[gl] ) ) ;
- gaugeLabel[gl].y = y ;
- gaugeLabel[gl].text = gaugeText[gl] ;
- gl++ ;
- interpVec3( laserBG.v0, x, botBack, botFront ) ;
- interpVec3( laserBG.v4, x, topBack, topFront ) ;
- x += width ;
- interpVec3( laserBG.v1, x, botBack, botFront ) ;
- interpVec3( laserBG.v5, x, topBack, topFront ) ;
- laserBG.fg = 0x000000ff ;
- laserBG.bg = 0x00000000 ;
- setBarGraph( &laserBG, 0.8f ) ;
- x += gap ;
-
- /*
- * Locate cloak guage.
- */
- gaugeLabel[gl].x = x * l +
- 0.5f * ( l * width - getStrWidth( hf, gaugeText[gl] ) ) ;
- gaugeLabel[gl].y = y ;
- gaugeLabel[gl].text = gaugeText[gl] ;
- gl++ ;
- interpVec3( cloakBG.v0, x, botBack, botFront ) ;
- interpVec3( cloakBG.v4, x, topBack, topFront ) ;
- x += width ;
- interpVec3( cloakBG.v1, x, botBack, botFront ) ;
- interpVec3( cloakBG.v5, x, topBack, topFront ) ;
- cloakBG.fg = 0x000000ff ;
- cloakBG.bg = 0x00000000 ;
- setBarGraph( &cloakBG, 0.0f ) ;
- x += gap ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Interpret between two points: a = v * b + ( 1 - v ) * c.
- *----------------------------------------------------------------------------*/
- static void
- interpVec3(
- pfVec3 a,
- float v,
- pfVec3 b,
- pfVec3 c
- )
- {
- float vm = 1.0f - v ;
-
- PFCOMBINE_VEC3( a, vm, b, v, c ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show the text output area.
- *----------------------------------------------------------------------------*/
- static void
- showText(
- void
- )
- {
- int i ;
- int n ;
- float x ;
- float y ;
-
- pfPushMatrix() ;
- translate( textScreenBL[0], textScreenBL[1], textScreenBL[2] ) ;
- rot( textScreenRotY, 'y' ) ;
- rot( textScreenRotX, 'x' ) ;
- cpack( 0x0 ) ;
- rectf( 0.0f, 0.0f, textScreenW, textScreenH ) ;
- x = 0.1f * textScreenFontSize ;
- y = 0.1f * textScreenFontSize ;
-
- if( reformatMessage )
- {
- formatMessage() ;
- reformatMessage = 0 ;
- }
-
- cpack( 0x0000ffff ) ;
- for( i = nMsgLines - 1 ; i >= 0 ; i-- )
- {
- positionText( x, y ) ;
- drawString( cf, msgLines[i] ) ;
- y += textScreenFontSize ;
- }
- cpack( 0x000000ff ) ;
- for( i = 0 ; i < nTextLines - nMsgLines ; i++ )
- {
- n = ( textScreenLine + i ) % nTextLines ;
- positionText( x, y ) ;
- drawString( cf, textLines[n] ) ;
- y += textScreenFontSize ;
- }
- pfPopMatrix() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize dashboard stuff.
- *----------------------------------------------------------------------------*/
- void
- initDashboard(
- void
- )
- {
- cf = loadFont( "c.oort" ) ;
-
- hf = copyFont( helvFont ) ;
-
- sf = copyFont( hf ) ;
- setFontSize( sf, 0.09f ) ;
-
- locateGauges() ;
-
- initTextScreen() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Dashboard draw callback.
- *----------------------------------------------------------------------------*/
- void
- drawDashboardChannel(
- pfChannel *channel,
- void *data
- )
- {
- pfPushState() ;
-
- pfBasicState() ;
-
- pfLightOff( Sun ) ;
-
- zfunction( ZF_ALWAYS ) ;
- zwritemask( 0x0 ) ;
-
- pfShadeModel( PFSM_FLAT ) ;
-
- viewport( dashboardVP.left, dashboardVP.right, dashboardVP.bottom,
- dashboardVP.top ) ;
- pfPushIdentMatrix() ;
- perspective( dashboardFOV, dashboardAR, dashboardNear, dashboardFar ) ;
- rot( dashboardAngle, 'x' ) ;
-
- if( needToRepaint )
- {
- needToRepaint = 0 ;
- frontbuffer( 1 ) ;
- repaintDashboard() ;
- frontbuffer( 0 ) ;
- }
-
- /*
- * Update gauges.
- */
- if( speed < 0.0f )
- {
- speedometerBG.fg = 0x000000ff ;
- setBarGraph( &speedometerBG, -speed / topSpeed ) ;
- }
- else
- {
- speedometerBG.fg = 0x0000ff00 ;
- setBarGraph( &speedometerBG, speed / topSpeed ) ;
- }
- showBarGraph( &speedometerBG ) ;
-
- if( shields > 0.50f )
- shieldsBG.fg = 0x0000ff00 ;
- else if( shields > 0.25f )
- shieldsBG.fg = 0x0000ffff ;
- else
- shieldsBG.fg = 0x000000ff ;
- setBarGraph( &shieldsBG, shields ) ;
- showBarGraph( &shieldsBG ) ;
-
- if( power > 0.50f )
- powerBG.fg = 0x0000ff00 ;
- else if( power > 0.25f )
- powerBG.fg = 0x0000ffff ;
- else
- powerBG.fg = 0x000000ff ;
- setBarGraph( &powerBG, power ) ;
- showBarGraph( &powerBG ) ;
-
- setBarGraph( &laserBG, laser ) ;
- showBarGraph( &laserBG ) ;
-
- setBarGraph( &cloakBG, cloak ) ;
- showBarGraph( &cloakBG ) ;
-
- if( repaintTextScreen > 0 )
- {
- showText() ;
- repaintTextScreen-- ;
- }
-
- if( repaintScores > 0 )
- {
- showScores() ;
- repaintScores-- ;
- }
-
- if( repaintPlayers > 0 )
- {
- showPlayers() ;
- repaintPlayers-- ;
- }
-
- showHeading() ;
- pfPopMatrix() ;
-
- pfPushIdentMatrix() ;
- showRadar() ;
- pfPopMatrix() ;
-
- zfunction( ZF_LEQUAL ) ;
- zwritemask( 0xffffffff ) ;
-
- pfPopState() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show the compass heading.
- *----------------------------------------------------------------------------*/
- static void
- showHeading(
- void
- )
- {
- static int buf = 0 ;
- static float lastHeading[2] = { 0.0f, 0.0f } ;
-
- pfPushState();
- pfBasicState();
-
- pfPushMatrix() ;
- translate( 0.0f, -1.0f, -1.45f ) ;
-
- /*
- * Erase previous arrow.
- */
- pfPushMatrix() ;
- rot( lastHeading[buf], 'y' ) ;
- cpack( 0x0 ) ;
- bgntmesh() ;
- v3f( compassArrow[0] ) ;
- v3f( compassArrow[1] ) ;
- v3f( compassArrow[2] ) ;
- v3f( compassArrow[3] ) ;
- endtmesh() ;
- pfPopMatrix() ;
-
- /*
- * Draw current arrow.
- */
- lastHeading[buf] = -getHeading() ;
- rot( lastHeading[buf], 'y' ) ;
- cpack( 0x000000ff ) ;
- bgntmesh() ;
- v3f( compassArrow[0] ) ;
- v3f( compassArrow[1] ) ;
- v3f( compassArrow[2] ) ;
- v3f( compassArrow[3] ) ;
- endtmesh() ;
-
- buf = ( buf + 1 ) % 2 ;
-
- pfPopMatrix() ;
- pfPopState();
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize stuff for the text screen.
- *----------------------------------------------------------------------------*/
- static void
- initTextScreen(
- void
- )
- {
- int i ;
- float d ;
- pfVec3 a ;
- pfVec3 up ;
- pfVec3 v35 ;
- pfVec3 bottom ;
- pfVec3 side ;
- pfVec3 v ;
-
- /*
- * Set up for locating gauges along left side.
- */
- PFSUB_VEC3( bottom, backPanel[5], backPanel[3] ) ;
- PFSUB_VEC3( side, backPanel[2], backPanel[3] ) ;
- PFCOPY_VEC3( v, side ) ;
-
- pfNormalizeVec3( bottom ) ;
- d = -PFDOT_VEC3( bottom, side ) ;
- OFFSET_VEC3( side, d, bottom );
- pfNormalizeVec3( side ) ;
-
- textScreenW = 0.80f * pfDistancePt3( backPanel[3], backPanel[5] ) ;
- textScreenH = 0.80f * PFDOT_VEC3( v, side ) ;
-
- textScreenFontSize = textScreenH / (float)nTextLines ;
-
- setFontSize( cf, textScreenFontSize ) ;
-
- textScreenRotY = pfArcTan2( -bottom[2], bottom[0] ) ;
-
- pfCrossVec3( v, bottom, side ) ;
- textScreenRotX = pfArcSin( -v[1] ) ;
-
- ADDSCALE_VEC3( textScreenBL, backPanel[3], 0.15f * textScreenW,
- bottom ) ;
- ADDSCALE_VEC3( textScreenBL, textScreenBL, 0.15f * textScreenH,
- side ) ;
-
- ADDSCALE_VEC3( textScreenBR, textScreenBL, textScreenW, bottom );
- ADDSCALE_VEC3( textScreenTL, textScreenBL, textScreenH, side ) ;
- ADDSCALE_VEC3( textScreenTR, textScreenTL, textScreenW, bottom );
-
- for( i = 0 ; i < nTextLines ; i++ )
- {
- textLines[i][0] = '\0' ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Post a new message to the text screen.
- *----------------------------------------------------------------------------*/
- void
- postNewMessage(
- char *fmt,
- ...
- )
- {
- va_list args ;
- int ncSeen ;
- int i ;
- int start = 0 ;
- char msg[512] ;
-
- va_start( args, fmt ) ;
- vsprintf( msg, fmt, args ) ;
-
- ncSeen = maxCharsInWidth( cf, msg, textScreenW ) ;
-
- if( ncSeen < 1 )
- return ;
-
- while( strlen( msg+start ) > ncSeen )
- {
- for( i = ncSeen ; i > 0 && msg[start+i] != ' ' ; i-- )
- {
- }
-
- textScreenLine = ( textScreenLine + nTextLines - 1 )
- % nTextLines ;
- if( i == 0 )
- {
- i = ncSeen ;
- }
- strncpy( textLines[textScreenLine], msg+start, i ) ;
- textLines[textScreenLine][i] = '\0' ;
-
- start += i ;
- }
-
- if( msg[start] != '\0' )
- {
- textScreenLine = ( textScreenLine + nTextLines - 1 )
- % nTextLines ;
- strncpy( textLines[textScreenLine], msg+start, MAX_MSG_SIZE ) ;
- }
- repaintTextScreen = 2 ;
-
- va_end( args ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw frames around all of the gauges.
- *----------------------------------------------------------------------------*/
- static void
- drawFrames(
- void
- )
- {
- pfVec3 tl ;
- pfVec3 tr ;
- pfVec3 bl ;
- pfVec3 br ;
- long dark0 = 0x00101010 ;
- long dark1 = 0x00202020 ;
- long dark2 = 0x00404040 ;
- long dark3 = 0x00707070 ;
- long dark4 = 0x00a0a0a0 ;
- long none = -1 ;
-
- /*
- * Radar frame.
- */
- PFSET_VEC3( tl, radarCorner[0][0], radarCorner[1][1],
- radarCorner[1][2] );
- PFSET_VEC3( tr, radarCorner[1][0], radarCorner[1][1],
- radarCorner[1][2] );
- PFSET_VEC3( bl, radarCorner[0][0], radarCorner[0][1],
- radarCorner[0][2] );
- PFSET_VEC3( br, radarCorner[1][0], radarCorner[0][1],
- radarCorner[0][2] );
- drawOneFrame( tl, tr, bl, br, dark1, dark2, dark2, dark4 ) ;
-
- /*
- * Bar graph frames.
- */
- drawOneFrame( speedometerBG.v4, speedometerBG.v5, speedometerBG.v0,
- speedometerBG.v1, dark0, dark1, none, dark4 ) ;
- drawOneFrame( shieldsBG.v4, shieldsBG.v5, shieldsBG.v0,
- shieldsBG.v1, dark0, dark1, none, dark4 ) ;
- drawOneFrame( powerBG.v4, powerBG.v5, powerBG.v0,
- powerBG.v1, dark0, dark1, none, dark4 ) ;
- drawOneFrame( laserBG.v4, laserBG.v5, laserBG.v0,
- laserBG.v1, dark0, dark1, none, dark4 ) ;
- drawOneFrame( cloakBG.v4, cloakBG.v5, cloakBG.v0,
- cloakBG.v1, dark0, dark1, none, dark4 ) ;
-
- /*
- * Text screen frame.
- */
- drawOneFrame( textScreenTL, textScreenTR, textScreenBL,
- textScreenBR, dark0, none, dark2, dark4 ) ;
-
- /*
- * Compass frame.
- */
- drawOneFrame( compassFrame[1], compassFrame[0], compassFrame[3],
- compassFrame[2], dark2, dark3, dark3, none ) ;
-
- /*
- * Kill counter frame.
- */
- drawOneFrame( killsFrame[1], killsFrame[0], killsFrame[3],
- killsFrame[2], dark2, dark3, dark3, none ) ;
-
- /*
- * Life counter frame.
- */
- drawOneFrame( livesFrame[1], livesFrame[0], livesFrame[3],
- livesFrame[2], dark2, dark3, dark3, none ) ;
-
- /*
- * Player counter frame.
- */
- drawOneFrame( playersFrame[1], playersFrame[0], playersFrame[3],
- playersFrame[2], dark2, dark3, dark3, none ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw a frame.
- *----------------------------------------------------------------------------*/
- static void
- drawOneFrame(
- pfVec3 tl,
- pfVec3 tr,
- pfVec3 bl,
- pfVec3 br,
- long topColor,
- long leftColor,
- long rightColor,
- long bottomColor
- )
- {
- float dl ;
- float dr ;
- float dt ;
- float db ;
- pfVec3 otl ;
- pfVec3 otr ;
- pfVec3 obl ;
- pfVec3 obr ;
- pfVec3 v ;
- pfVec3 h ;
- pfVec3 u ;
-
- PFSUB_VEC3( v, tl, bl ) ;
- pfNormalizeVec3( v ) ;
- PFSUB_VEC3( h, tr, tl ) ;
- pfNormalizeVec3( h ) ;
- pfCrossVec3( u, h, v ) ;
- PFSCALE_VEC3( u, 0.005f, u ) ;
-
- dl = ( leftColor == -1 ) ? 0.0f : -0.01f ;
- dr = ( rightColor == -1 ) ? 0.0f : 0.01f ;
- dt = ( topColor == -1 ) ? 0.0f : 0.01f ;
- db = ( bottomColor == -1 ) ? 0.0f : -0.01f ;
-
- PFCOMBINE_VEC3( otl, dl, h, dt, v ) ;
- PFADD_VEC3( otl, otl, tl ) ;
- PFADD_VEC3( otl, otl, u ) ;
-
- PFCOMBINE_VEC3( otr, dr, h, dt, v ) ;
- PFADD_VEC3( otr, otr, tr ) ;
- PFADD_VEC3( otr, otr, u ) ;
-
- PFCOMBINE_VEC3( obl, dl, h, db, v ) ;
- PFADD_VEC3( obl, obl, bl ) ;
- PFADD_VEC3( obl, obl, u ) ;
-
- PFCOMBINE_VEC3( obr, dr, h, db, v ) ;
- PFADD_VEC3( obr, obr, br ) ;
- PFADD_VEC3( obr, obr, u ) ;
-
- if( leftColor != -1 )
- {
- cpack( leftColor ) ;
- bgntmesh() ;
- v3f( obl ) ;
- v3f( bl ) ;
- v3f( otl ) ;
- v3f( tl ) ;
- endtmesh() ;
- }
-
- if( rightColor != -1 )
- {
- cpack( rightColor ) ;
- bgntmesh() ;
- v3f( br ) ;
- v3f( obr ) ;
- v3f( tr ) ;
- v3f( otr ) ;
- endtmesh() ;
- }
-
- if( topColor != -1 )
- {
- cpack( topColor ) ;
- bgntmesh() ;
- v3f( otl ) ;
- v3f( tl ) ;
- v3f( otr ) ;
- v3f( tr ) ;
- endtmesh() ;
- }
-
- if( bottomColor != -1 )
- {
- cpack( bottomColor ) ;
- bgntmesh() ;
- v3f( bl ) ;
- v3f( obl ) ;
- v3f( br ) ;
- v3f( obr ) ;
- endtmesh() ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Prepare to send a message.
- *----------------------------------------------------------------------------*/
- void
- initMessage(
- char mode
- )
- {
- mailMode = mode ;
- if( mode == MAIL_ALL )
- {
- postNewMessage( "Enter message:" ) ;
- }
- else
- {
- postNewMessage( "Enter team message:" ) ;
- }
- sendingMessage = 1 ;
- nMsgChars = 0 ;
- message[nMsgChars] = '_' ;
- message[nMsgChars+1] = '\0' ;
- nMsgLines = 1 ;
- repaintTextScreen = 2 ;
- reformatMessage = 1 ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Add to the message.
- *----------------------------------------------------------------------------*/
- void
- addToMessage(
- char c
- )
- {
- if( c == '\010' )
- {
- if( nMsgChars > 0 )
- {
- message[--nMsgChars] = '_' ;
- message[nMsgChars+1] = '\0' ;
- repaintTextScreen = 2 ;
- reformatMessage = 1 ;
- }
- }
- else if( c == '\015' )
- {
- sendingMessage = 0 ;
- message[nMsgChars] = '\0' ;
- if( mailMode == MAIL_ALL )
- {
- postNewMessage( "Message sent." ) ;
- }
- else
- {
- postNewMessage( "Team message sent." ) ;
- }
- nMsgLines = 0 ;
- if( nMsgChars )
- {
- mailMessage( mailMode, message ) ;
- }
- }
- else if( nMsgChars < MAX_MSG_SIZE - 1 )
- {
- repaintTextScreen = 2 ;
- reformatMessage = 1 ;
-
- message[nMsgChars++] = c ;
- if( nMsgChars < MAX_MSG_SIZE - 1 )
- {
- message[nMsgChars] = '_' ;
- message[nMsgChars+1] = '\0' ;
- }
- else
- {
- message[nMsgChars] = '\0' ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Format the message.
- *----------------------------------------------------------------------------*/
- static void
- formatMessage(
- void
- )
- {
- int ncSeen ;
- int i ;
- int start = 0 ;
-
- ncSeen = maxCharsInWidth( cf, message, textScreenW ) ;
-
- nMsgLines = 0 ;
-
- if( ncSeen < 1 )
- {
- msgLines[nMsgLines][0] = '\0' ;
- return ;
- }
-
- while( strlen( message+start ) > ncSeen && nMsgLines < MAX_MSG_LINES )
- {
- for( i = ncSeen ; i > 0 && message[start+i] != ' ' ; i-- )
- {
- }
-
- if( i == 0 )
- {
- i = ncSeen ;
- }
- strncpy( msgLines[nMsgLines], message+start, i ) ;
- msgLines[nMsgLines][i] = '\0' ;
- nMsgLines++ ;
-
- start += i ;
- }
-
- if( message[start] != '\0' && nMsgLines < MAX_MSG_LINES )
- {
- strncpy( msgLines[nMsgLines], message+start, MAX_MSG_SIZE ) ;
- nMsgLines++ ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw kills and lives counters.
- *----------------------------------------------------------------------------*/
- static void
- showScores(
- void
- )
- {
- char str[10] ;
-
- cpack( 0x0 ) ;
-
- /*
- * Draw kills counter background.
- */
- bgntmesh() ;
- v3f( killsFrame[0] ) ;
- v3f( killsFrame[1] ) ;
- v3f( killsFrame[2] ) ;
- v3f( killsFrame[3] ) ;
- endtmesh() ;
-
- /*
- * Draw lives counter background.
- */
- bgntmesh() ;
- v3f( livesFrame[0] ) ;
- v3f( livesFrame[1] ) ;
- v3f( livesFrame[2] ) ;
- v3f( livesFrame[3] ) ;
- endtmesh() ;
-
- pfPushMatrix() ;
- cpack( 0x00ffffff ) ;
- translate( killsFrame[2][0], killsFrame[2][1], killsFrame[2][2] ) ;
- rot( -90.0f, 'x' ) ;
- sprintf( str, "%d", kills ) ;
- positionText( -0.01f - getStrWidth( sf, str ), 0.0f ) ;
- drawString( sf, str ) ;
- pfPopMatrix() ;
-
- pfPushMatrix() ;
- cpack( 0x00ffffff ) ;
- translate( livesFrame[2][0], livesFrame[2][1], livesFrame[2][2] ) ;
- rot( -90.0f, 'x' ) ;
- sprintf( str, "%d", lives ) ;
- positionText( -0.01f - getStrWidth( sf, str ), 0.0f ) ;
- drawString( sf, str ) ;
- pfPopMatrix() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Increment the kill counter.
- *----------------------------------------------------------------------------*/
- void
- addKill(
- void
- )
- {
- kills++ ;
- repaintScores = 2 ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Increment the life counter.
- *----------------------------------------------------------------------------*/
- void
- addLife(
- void
- )
- {
- lives++ ;
- repaintScores = 2 ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw player counters.
- *----------------------------------------------------------------------------*/
- static void
- showPlayers(
- void
- )
- {
- char str[10] ;
-
- cpack( 0x0 ) ;
-
- /*
- * Draw players counter background.
- */
- bgntmesh() ;
- v3f( playersFrame[0] ) ;
- v3f( playersFrame[1] ) ;
- v3f( playersFrame[2] ) ;
- v3f( playersFrame[3] ) ;
- endtmesh() ;
-
- pfPushMatrix() ;
- cpack( 0x00ffffff ) ;
- translate( playersFrame[2][0], playersFrame[2][1], playersFrame[2][2] );
- rot( -90.0f, 'x' ) ;
- sprintf( str, "%d", numberPlayers ) ;
- positionText( -0.01f - getStrWidth( sf, str ), 0.0f ) ;
- drawString( sf, str ) ;
- pfPopMatrix() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Trigger player counter repaint.
- *----------------------------------------------------------------------------*/
- void
- updatePlayerCounter(
- void
- )
- {
- repaintPlayers = 2 ;
- }
-